#!/bin/bash
###SHELLPACK preamble libmicro-memory-bench 1

###SHELLPACK parseargBegin
###SHELLPACK parseargInstall
###SHELLPACK parseargEnd
###SHELLPACK monitor_hooks

###SHELLPACK check_install_required libmicro-memory-${VERSION}
###SHELLPACK init_complete

cd $SHELLPACK_SOURCES/libmicro-memory-${VERSION}-installed || die "Failed to cd to libmicro directory"

COMMON="-E -C 0 -D 30000 -B 10000 -L -S -W"

while read A B C; do
	monitor_pre_hook $LOGDIR_RESULTS $A-$B
	if [ -f bin/$A ]; then
		eval bin/$A $COMMON -N "$B" $C 2>&1 > $LOGDIR_RESULTS/$B.log
	fi
	monitor_post_hook $LOGDIR_RESULTS $A-$B
done <<EOT
memset	memset_10	-s 10
memset	memset_256	-s 256
memset	memset_256_u	-s 256	 -a 1
memset	memset_1k	-s 1k
memset	memset_4k	-s 4k
memset	memset_4k_uc	-s 4k -u
memset	memset_10k	-s 10k
memrand	memrand	-s 128m
cachetocache	cachetocache	-s 100k -T 2
malloc	malloc_10	-s 10 -g 10
malloc	malloc_100	-s 100 -g 10
malloc	malloc_1k	-s 1k -g 10
malloc	malloc_10k	-s 10k -g 10
malloc	malloc_100k	-s 100k -g 10
malloc	mallocT2_10	-s 10 -g 10 -T 2
malloc	mallocT2_100	-s 100 -g 10 -T 2
malloc	mallocT2_1k	-s 1k -g 10 -T 2
malloc	mallocT2_10k	-s 10k -g 10 -T 2
memcpy	memcpy_10	-s 10
memcpy	memcpy_1k	-s 1k
memcpy	memcpy_10k	-s 10k
strcpy	strcpy_10	-s 10
strcpy	strcpy_1k	-s 1k
strlen	strlen_10	-s 10
strlen	strlen_1k	-s 1k
strchr	strchr_10	-s 10
strchr	strchr_1k	-s 1k
strcmp	strcmp_10	-s 10
strcmp	strcmp_1k	-s 1k
strcasecmp	scasecmp_10	-s 10
strcasecmp	scasecmp_1k	-s 1k
mmap	mmap_z8k	-l 8k		-f /dev/zero
mmap	mmap_z128k	-l 128k		-f /dev/zero
mmap	mmap_a8k	-l 8k		-f MAP_ANON
mmap	mmap_a128k	-l 128k		-f MAP_ANON
mmap	mmap_rz8k	-l 8k -r	-f /dev/zero
mmap	mmap_rz128k	-l 128k -r	-f /dev/zero
mmap	mmap_ra8k	-l 8k -r	-f MAP_ANON
mmap	mmap_ra128k	-l 128k -r	-f MAP_ANON
mmap	mmap_wz8k	-l 8k -w	-f /dev/zero
mmap	mmap_wa8k	-l 8k -w	-f MAP_ANON
munmap	unmap_z8k	-l 8k		-f /dev/zero
munmap	unmap_z128k	-l 128k		-f /dev/zero
munmap	unmap_a8k	-l 8k		-f MAP_ANON
munmap	unmap_a128k	-l 128k		-f MAP_ANON
munmap	unmap_rz8k	-l 8k	-r	-f /dev/zero
munmap	unmap_rz128k	-l 128k -r	-f /dev/zero
munmap	unmap_ra8k	-l 8k	-r	-f MAP_ANON
munmap	unmap_ra128k	-l 128k	-r	-f MAP_ANON
munmap	unmap_wz8k	-l 8k	-w	-f /dev/zero
munmap	unmap_wa8k	-l 8k	-w	-f MAP_ANON
mprotect	mprot_z8k	-l 8k			-f /dev/zero
mprotect	mprot_z128k	-l 128k		-f /dev/zero
mprotect	mprot_wz8k	-l 8k	-w	-f /dev/zero
mprotect	mprot_wz128k	-l 128k	-w	-f /dev/zero
mprotect	mprot_twz8k	-l 8k -w -t -f /dev/zero
mprotect	mprot_tw128k	-l 128k -w -t -f /dev/zero
pipe	pipe_pst1	-s 1	-x pipe -m st
pipe	pipe_pmt1	-s 1	-x pipe -m mt
pipe	pipe_pmp1	-s 1	-x pipe -m mp
pipe	pipe_pst4k	-s 4k	-x pipe -m st
pipe	pipe_pmt4k	-s 4k	-x pipe -m mt
pipe	pipe_pmp4k	-s 4k	-x pipe -m mp
pipe	pipe_sst1	-s 1	-x sock -m st
pipe	pipe_smt1	-s 1	-x sock -m mt
pipe	pipe_smp1	-s 1	-x sock -m mp
pipe	pipe_sst4k	-s 4k	-x sock -m st
pipe	pipe_smt4k	-s 4k	-x sock -m mt
pipe	pipe_smp4k	-s 4k	-x sock -m mp
pipe	pipe_tst1	-s 1	-x tcp -m st
pipe	pipe_tmt1	-s 1	-x tcp -m mt
pipe	pipe_tmp1	-s 1	-x tcp -m mp
pipe	pipe_tst4k	-s 4k	-x tcp -m st
pipe	pipe_tmt4k	-s 4k	-x tcp -m mt
pipe	pipe_tmp4k	-s 4k	-x tcp -m mp
EOT

exit $SHELLPACK_SUCCESS
